#include "MySignal.h"
#include <signal.h>

namespace XIAOO{
    
    void MySignal::registMySignal(int listenfd){
        XIAOO::signal_listenfd = listenfd;
        std::cout<<"register my signal"<<std::endl;
        signal(SIGCHLD, MySignal::handleSigChild);
        signal(SIGINT, MySignal::handleSigInit);
    }

    void MySignal::handleSigChild(int sig){
        std::cout<<"handle child"<<std::endl;
    }

    void MySignal::handleSigInit(int sig){
        std::cout<<"handle init"<<std::endl;
        if(XIAOO::signal_listenfd){
            std::cout<<"close listenfd"<<std::endl;
            close(XIAOO::signal_listenfd);
        }
        exit(0);
    }

    MySignal::MySignal(){

    }

    MySignal::~MySignal(){
        
    }
}